
from datetime import datetime
from util import *

def getETFHolding(code):
    # 目标 URL
    base_url = "https://query.sse.com.cn/commonQuery.do?FUNDID2={}&sqlId=COMMON_SSE_CP_JJLB_ETFJJGK_GGSGSHQD_COMPONENT_C"
    url = base_url.format(code)

    # 完全匹配Apifox中的请求头设置
    headers = {
        "Referer": "https://www.sse.com.cn/"
    }
    
    return get_with_headers_requests(url, headers, True)

# 保存上一个工作日的持仓情况
def saveShangHoding(code):
    yesterday = get_previous_workday_with_holidays(datetime.now().date())
    # dateformat ： yyyyMMdd
    resp = getETFHolding(code)
    hodingResult = resp.get("result")
    save_to_csv(hodingResult,code,yesterday)

if __name__ == "__main__":
  saveShangHoding("563020")